import React, { useEffect, useMemo, useState } from 'react';
import List from 'devextreme-react/list';
import getApiData from '@/services/cpasRequest';
import notify from 'devextreme/ui/notify';
/**
 * 审计底稿 Sheets
 * @param props
 * @returns
 */
const DgSheets: React.FC<any> = (props: any) =>{ 
  const { dbname, dgid } = props; 
  const [ data, setData ] = useState<any[]>([]);
  // 获取 审计阶段列表
  const fetchData = async () => {
    const res = await getApiData('sjdg.sheets', {dbname, dgid});
    if (res.ok) {
      setData(res.data)
    } else {
      notify(res.data, 'error');
    }
  };

  useEffect(() => {
    // if (dbname !== '') {
      fetchData();
    // }
  }, [dbname, dgid]);

  function renderSheet(){
      return <List
      dataSource={data}
      // searchEnabled={true}
      // searchMode='contains'
      height="100%"
      itemRender={(item) => {
        // console.log(item);
        return <>
          <div>
            {item.sheetIndex} {item.sheetName}
          </div>
          <div className='row-user'>{item.editUser}</div>
        </> 
      }}
    />
  }
  
  return (
     <>
      {
        useMemo(()=>{
          return renderSheet()
        },[data])
      }
     </>
  )
};

export default DgSheets;